
/**
 * from http://stackoverflow.com/questions/15308371/custom-events-model-without-using-dom-events-in-javascript
 * 
 * Use it like DOM events model

var subup_tiny = new Subup_Tiny();

subup_tiny.registerEvent('big bang');

subup_tiny.addEventListener('big bang', function(){
  console.log('This is big bang listener yo!');
});

subup_tiny.addEventListener('big bang', function(){
  console.log('This is another big bang listener yo!');
});

subup_tiny.dispatchEvent('big bang');
 */

/**
 * todo: priority & context
 */
function Event(name){
  this.name = name;
  this.callbacks = [];
}

Event.prototype.registerCallback = function(callback){
  this.callbacks.push(callback);
};

function Subup_Tiny(){
  this.events = {};
}

Subup_Tiny.prototype.registerEvent = function(eventName){
  var event = new Event(eventName);
  this.events[eventName] = event;
};

Subup_Tiny.prototype.dispatchEvent = function(eventName, eventArgs){
  this.events[eventName].callbacks.forEach(function(callback){
    callback(eventArgs);
  });
};

Subup_Tiny.prototype.addEventListener = function(eventName, callback){
  this.events[eventName].registerCallback(callback);
};

